using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class HRM_PROCESS_RATEDETAILData : DatabaseObjectBase
	{
		public HRM_PROCESS_RATEDETAILData()
		{
			Initialize(true);
		}
		public HRM_PROCESS_RATEDETAILData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 HRM_PROCESS_RATEDETAIL_Insert(Guid RateDetailID, Guid RateID, String Content, Double Coefficient, Double SelfScore, String SelfRate, Double Score, String Rate, Int32 Sort)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("HRM_PROCESS_RATEDETAIL_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@RateDetailID", SqlDbType.UniqueIdentifier));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@RateID", SqlDbType.UniqueIdentifier));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Content", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Coefficient", SqlDbType.Float));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@SelfScore", SqlDbType.Float));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@SelfRate", SqlDbType.NVarChar, 50));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Score", SqlDbType.Float));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Rate", SqlDbType.NVarChar, 50));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Sort", SqlDbType.Int));
				_dbadapter.InsertCommand.Prepare();
				SqlGuid RateDetailIDSQL = RateDetailID;
				_dbadapter.InsertCommand.Parameters["@RateDetailID"].Value = RateDetailIDSQL;
				SqlGuid RateIDSQL = RateID;
				_dbadapter.InsertCommand.Parameters["@RateID"].Value = RateIDSQL;
				SqlString ContentSQL = Content;
				_dbadapter.InsertCommand.Parameters["@Content"].Value = ContentSQL;
				SqlDouble CoefficientSQL = Coefficient;
				_dbadapter.InsertCommand.Parameters["@Coefficient"].Value = CoefficientSQL;
				SqlDouble SelfScoreSQL = SelfScore;
				_dbadapter.InsertCommand.Parameters["@SelfScore"].Value = SelfScoreSQL;
				SqlString SelfRateSQL = SelfRate;
				_dbadapter.InsertCommand.Parameters["@SelfRate"].Value = SelfRateSQL;
				SqlDouble ScoreSQL = Score;
				_dbadapter.InsertCommand.Parameters["@Score"].Value = ScoreSQL;
				SqlString RateSQL = Rate;
				_dbadapter.InsertCommand.Parameters["@Rate"].Value = RateSQL;
				SqlInt32 SortSQL = Sort;
				_dbadapter.InsertCommand.Parameters["@Sort"].Value = SortSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_RATEDETAIL_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_RATEDETAIL_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_RATEDETAIL_Update(Guid RateDetailID, Guid RateID, String Content, Double Coefficient, Double SelfScore, String SelfRate, Double Score, String Rate, Int32 Sort)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_RATEDETAIL_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RateDetailID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RateID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Content", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Coefficient", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SelfScore", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SelfRate", SqlDbType.NVarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Score", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Rate", SqlDbType.NVarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Sort", SqlDbType.Int));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid RateDetailIDSQL = RateDetailID;
				_dbadapter.UpdateCommand.Parameters["@RateDetailID"].Value = RateDetailIDSQL;
				SqlGuid RateIDSQL = RateID;
				_dbadapter.UpdateCommand.Parameters["@RateID"].Value = RateIDSQL;
				SqlString ContentSQL = Content;
				_dbadapter.UpdateCommand.Parameters["@Content"].Value = ContentSQL;
				SqlDouble CoefficientSQL = Coefficient;
				_dbadapter.UpdateCommand.Parameters["@Coefficient"].Value = CoefficientSQL;
				SqlDouble SelfScoreSQL = SelfScore;
				_dbadapter.UpdateCommand.Parameters["@SelfScore"].Value = SelfScoreSQL;
				SqlString SelfRateSQL = SelfRate;
				_dbadapter.UpdateCommand.Parameters["@SelfRate"].Value = SelfRateSQL;
				SqlDouble ScoreSQL = Score;
				_dbadapter.UpdateCommand.Parameters["@Score"].Value = ScoreSQL;
				SqlString RateSQL = Rate;
				_dbadapter.UpdateCommand.Parameters["@Rate"].Value = RateSQL;
				SqlInt32 SortSQL = Sort;
				_dbadapter.UpdateCommand.Parameters["@Sort"].Value = SortSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_RATEDETAIL_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_RATEDETAIL_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_RATEDETAIL_Disable(Guid RateDetailID, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_RATEDETAIL_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RateDetailID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid RateDetailIDSQL = RateDetailID;
				_dbadapter.UpdateCommand.Parameters["@RateDetailID"].Value = RateDetailIDSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_RATEDETAIL_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_RATEDETAIL_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_RATEDETAIL_Delete(Guid RateDetailID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("HRM_PROCESS_RATEDETAIL_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@RateDetailID", SqlDbType.UniqueIdentifier));
				_dbadapter.DeleteCommand.Prepare();
				SqlGuid RateDetailIDSQL = RateDetailID;
				_dbadapter.DeleteCommand.Parameters["@RateDetailID"].Value = RateDetailIDSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_RATEDETAIL_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_RATEDETAIL_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_RATEDETAIL_Save(Guid RateDetailID, Guid RateID, String Content, Double Coefficient, Double SelfScore, String SelfRate, Double Score, String Rate, Int32 Sort)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_RATEDETAIL_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RateDetailID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RateID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Content", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Coefficient", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SelfScore", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SelfRate", SqlDbType.NVarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Score", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Rate", SqlDbType.NVarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Sort", SqlDbType.Int));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid RateDetailIDSQL = RateDetailID;
				_dbadapter.UpdateCommand.Parameters["@RateDetailID"].Value = RateDetailIDSQL;
				SqlGuid RateIDSQL = RateID;
				_dbadapter.UpdateCommand.Parameters["@RateID"].Value = RateIDSQL;
				SqlString ContentSQL = Content;
				_dbadapter.UpdateCommand.Parameters["@Content"].Value = ContentSQL;
				SqlDouble CoefficientSQL = Coefficient;
				_dbadapter.UpdateCommand.Parameters["@Coefficient"].Value = CoefficientSQL;
				SqlDouble SelfScoreSQL = SelfScore;
				_dbadapter.UpdateCommand.Parameters["@SelfScore"].Value = SelfScoreSQL;
				SqlString SelfRateSQL = SelfRate;
				_dbadapter.UpdateCommand.Parameters["@SelfRate"].Value = SelfRateSQL;
				SqlDouble ScoreSQL = Score;
				_dbadapter.UpdateCommand.Parameters["@Score"].Value = ScoreSQL;
				SqlString RateSQL = Rate;
				_dbadapter.UpdateCommand.Parameters["@Rate"].Value = RateSQL;
				SqlInt32 SortSQL = Sort;
				_dbadapter.UpdateCommand.Parameters["@Sort"].Value = SortSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_RATEDETAIL_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_RATEDETAIL_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_PROCESS_RATEDETAIL_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_PROCESS_RATEDETAIL_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_PROCESS_RATEDETAIL_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_PROCESS_RATEDETAIL_Get(Guid RateDetailID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_PROCESS_RATEDETAIL_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@RateDetailID", SqlDbType.UniqueIdentifier));
				_dbadapter.SelectCommand.Prepare();
				SqlGuid RateDetailIDSQL = RateDetailID;
				_dbadapter.SelectCommand.Parameters["@RateDetailID"].Value = RateDetailIDSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_PROCESS_RATEDETAIL_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
	}
}
